import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import javax.sql.DataSource;
import java.sql.*;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("111111");

        Connection connection = dataSource.getConnection();

        String sql = "select * from borrow_info where book_id = 7 or book_id = 8  or book_id = 9 or book_id = 1";
        PreparedStatement statement = connection.prepareStatement(sql);
        System.out.println("sql = " + statement);

        ResultSet resultSet = statement.executeQuery();

        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            int book_id = resultSet.getInt("book_id");
            int student_id = resultSet.getInt("student_id");
            Timestamp start_time = resultSet.getTimestamp("start_time");
            Timestamp end_time = resultSet.getTimestamp("end_time");
            System.out.println("id:" + id + ", book_id:" + book_id + ", student_id:" + student_id + ", start_time:"
                    + start_time + ", end_time:" + end_time);
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}
